package com.kjc.demo.rcservice.service;

import java.util.List;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.kjc.demo.rcservice.bean.DocFolderBean;
import com.kjc.demo.rcservice.repository.DocFolderMapper;
import com.sdhs.paas.sdk.base.common.BaseDao;
import com.sdhs.paas.sdk.base.common.BasePage;
import com.sdhs.paas.sdk.base.common.entity.PaginationEntity;
import com.sdhs.paas.sdk.core.PaasBaseException;
import com.sdhs.paas.sdk.core.mybatis.EnablePaasMybatis;

/**
* 描述：DocFolderService 服务接口
* @author kangjichang
* @date 2018-12-06
*/

@EnablePaasMybatis
@MapperScan("com.kjc.demo.rcservice.repository")
@Service
public class DocFolderService extends BaseDao<DocFolderBean, DocFolderMapper, Integer>{
		@Override
		public String getMapperNamespace() {
			return DocFolderMapper.class.getName();
		}
		
		@Autowired
		private DocFolderMapper docFolderMapper;
		
		public PaginationEntity<DocFolderBean> getPageDocFolderList(BasePage pageRequest, DocFolderBean docFolderBean) {
			Page<DocFolderBean> pageTotal = PageHelper.startPage(pageRequest.getPage(), pageRequest.getPageSize(),true);
			List<DocFolderBean> list = docFolderMapper.getList(docFolderBean);
			PaginationEntity<DocFolderBean> paginationEntity = new PaginationEntity<DocFolderBean>(list,
	                (int) pageTotal.getTotal());
			return paginationEntity;
		}
		
		@Transactional(rollbackFor = Exception.class)
		public boolean saveDocFolder(DocFolderBean docFolderBean) {
			try {
				//ucAppBean.setCtime(System.currentTimeMillis());
				//ucAppBean.setUtime(System.currentTimeMillis());
				int count = docFolderMapper.insertDocFolder(docFolderBean);
				return count == 1;
			} catch (Exception e) {
				throw new PaasBaseException(e, "500", "数据库插入异常！");
			}
		}
	
		@Transactional(rollbackFor = Exception.class)
		public boolean updateDocFolder(DocFolderBean docFolderBean) {
			try {
				//ucAppBean.setUtime(System.currentTimeMillis());
				int count = docFolderMapper.updateDocFolder(docFolderBean);
				return count == 1;
			} catch (Exception e) {
				throw new PaasBaseException(e, "500", "数据库插入异常！");
			}
		}
	
		public DocFolderBean getDocFolderDetail(String id) {
			return docFolderMapper.getDocFolderDetail(id);
		}
		
		public boolean deleteDocFolder(DocFolderBean docFolderBean){
			return docFolderMapper.deleteDocFolder(docFolderBean)>0;
		}
      
}